<?php

Class indexController Extends baseController {

    public function index() 
    {
            $order = 1;
            $start = 1;
            $length =10;
            if(isset($_REQUEST["order"]))
            {
                $order = intval($_REQUEST["order"]);
            }
            $roomDAO = CreateObject("Model_DAO_Room");
            $rooms = $roomDAO->lists($order,$start,$length);
            $this->registry->template->rooms = $rooms;
            $this->registry->template->roomDAO = $roomDAO;
             
            $browser = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
            $browser1 = strpos($_SERVER['HTTP_USER_AGENT'],"iPad");
            if($browser == true || $browser1 == true)
            {
                 $this->registry->template->show('index_index_mobile'); 
            }
            else
            {
                $this->registry->template->show('index_index');
            }
            /*
            if($this->registry->mobile == "true")
            {
                $this->registry->template->show('index_index_mobile');
            }
            else
            {
                $this->registry->template->show('index_index');
            }*/
    }
    
    
    public function view(){
        if(isset($_REQUEST["id"])){
            $id = $_REQUEST["id"];
            $roomDAO = CreateObject("Model_DAO_Room");
            $room = $roomDAO->get($id);   
            $this->registry->template->room = $room;
               
            $browser = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
            $browser1 = strpos($_SERVER['HTTP_USER_AGENT'],"iPad");
            if($browser == true || $browser1 == true)
            {
                 $this->registry->template->show('index_view_mobile'); 
            }
            else
            {
               $this->registry->template->show('index_view');
            }
        }
    }
    
    public function comment()
    {
        try
        {
            if(isset($_REQUEST["idRoom"]))
            {
                $idRoom = $_POST["idRoom"];
                $comment_email = $_POST["comment_email"];
                $comment_name = $_POST["comment_name"];
                $comment_text = $_POST["comment_text"];
                $comment_title = $_POST["comment_title"];
                $commentDAO = CreateObject("Model_DAO_Comment");
                $status = $commentDAO->commentRoom($idRoom,$comment_title,$comment_text,$comment_name,$comment_email);
                if($status)
                    echo "true";
                else
                    echo "false";
            }
            else
            {
                echo  "false";
            }
        }
        catch(MyException $ex)
        {
            echo "false";  
        }
        
    }
}
?>